home *** CD-ROM | disk | FTP | other *** search
- (* UNIT Copyright (C) 1988 BTS Software
-
- Written by Larry Johnson 12/09/88
- BTS Software
- 825 Acton Ave
- Birmingham, AL 35209
- CompuServe: 73717,14
- BIX: lajohnson
-
- This program manages the procedure/function decelarations
- in the interface section of a unit by copying specified
- procedure/function headers from the implementation section
- into the interface section.
-
- Usage: C>UNIT filename
-
- Insert these codes in your Unit:
- {.I+} - start of procedure/function interface
- {.I-} - end of procedure/function interface
- {.U+} - include this procedure/function in interface
- {.U-} - stop including
-
- This program has a few limitations. If the keywords BEGIN, VAR,
- CONST, or TYPE appear in a comment following the declaration then
- the transfer to the interface will stop. Also these keywords should
- have at least one space after them or use the {.U-} switch. These
- limitations could be overcome by writing a parser that ignores anything
- in comments but until such a time you'll have to settle for the trade off.
- It also won't process include files. All code to be interfaced must be
- in the same physical unit file. Enjoy.
-
- Note: type, const, & var should NOT be placed between the {.I+}/{.I-}
- section; They will be erased!!! {U+} moves procedure/function
- headers only; no data declariations.
-
- **** An Example ****
-
- {-------------------------}
-
- Before:
-
- unit Sample ;
-
- interface
-
- {.I+} {Start of interface}
- {.I-} {End of interface}
- implementation
-
- {.U+} {Include this procedure in the interface}
- procedure Global(P1, P2 : word) ;
- begin
- end ;
-
- {.U-} {Don't Include this procedure in the interface}
- procedure UnitLocal(P1, P2 : word) ;
- begin
- end ;
-
- {-------------------------}
-
- After C>Unit Sample.pas:
-
- unit Sample ;
-
- interface
-
- {.I+} {Start of interface}
- New>
- New> procedure Global(P1, P2 : word) ;
- New>
- {.I-} {End of interface}
- implementation
-
- {.U+} {Include this procedure in the interface}
- procedure Global(P1, P2 : word) ;
- begin
- end ;
-
- {.U-} {Don't Include this procedure in the interface}
- procedure UnitLocal(P1, P2 : word) ;
- begin
- end ;
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% *)
-
- {$D-} { Debug information (Global) }
- {$L-} { Debug Local Symbols (Global) }
- {$A-} { Align Data (Global) }
- {$E-} { 8087 Emulation (Global) }
- {$N-} { Numeric CoProcessor (Global) }
- {$O-} { Overlay Code (Global) }
- {------------------------------------}
- {$B-} { Boolean evaluation }
- {$F-} { Force Far Calls }
- {$I-} { I/O checking }
- {$R-} { Range checking }
- {$S-} { Stack checking }
- {$V-} { Var-String checking }
-
- {$M $4000,0,$A0000} { Memory Allocation Sizes (MinStack,MinHeap,MaxHeap)}
-
- { %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% }
-
- program _Unit ;
-
- { %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% }
-
- const
- ProgramName = 'UNIT' ;
- Version = '1.0F' ;
- Compiled = '12/09/88' ;
-
- const
- InterfaceStart = '.I+' ; {Mark the Start of the interface area}
- InterfaceEnd = '.I-' ; {Mark the End of the interface area}
- IncludeOn = '.U+' ; {Mark procedure/function to be interfaced}
- IncludeOff = '.U-' ; {Stop interfacing}
-
- const
- TextBufSize = 8192 ; { Needs to be divisible by 128 }
-
- var
- InFile : text ;
- OutFile : text ;
- TmpFile : text ;
-
- InBuf : array[1..TextBufSize] of char ;
- OutBuf : array[1..TextBufSize] of char ;
- TmpBuf : array[1..TextBufSize] of char ;
-
- InFileName : string[64] ;
- OutFileName : string[64] ;
- TmpFileName : string[64] ;
-
- LineIn : string ;
- UCLineIn : string ;
- TLineIn : string ;
-
- SemiColon : boolean ;
- Writing : boolean ;
- CheckForCode : boolean ;
- BlankLine : boolean ;
-
- { %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% }
-
- function UpString(Wstr : string): string ;
- var loop : byte ;
- begin
- for loop := 1 to length(Wstr) do
- Wstr[loop] := UpCase(Wstr[loop]) ;
- UpString := Wstr ;
- end ;
-
- function DefExt(FileName, Ext : string): string ;
- begin
- if (pos('.', FileName) > 0)
- then DefExt := FileName
- else DefExt := FileName + '.' + Ext ;
- end;
-
- function ForceExt(FileName, Ext : string): string ;
- var Dot : byte ;
- begin
- Dot := pos('.', FileName) ;
- if (Dot > 0)
- then ForceExt := copy(FileName, 1, Dot) + Ext
- else ForceExt := FileName + '.' + Ext ;
- end;
-
- { %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% }
-
- function Contains(S : string): boolean ;
- begin
- Contains := (pos(S, UCLineIn) > 0) ; {global}
- end ;
-
- procedure WritingOn ;
- begin
- Writing := true ; {global}
- SemiColon := true ; {global}
- CheckForCode := false ; {global}
- BlankLine := true ; {global}
- end ;
-
- procedure WritingOff ;
- begin
- if Writing and
- BlankLine
- then writeln(OutFile) ; { make sure there is at least one blank line }
- Writing := false ; {global}
- end ;
-
- { %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% }
-
- begin
- writeln(#13, #10, ' ', ProgramName, ' V', Version, ' ', Compiled,
- ' Copyright (C) 1988 BTS Software', #13, #10) ;
-
- if (paramcount < 1) then { Help }
- begin
- writeln(' This program updates the procedure/function declarations') ;
- writeln(' in the interface of a unit based upon its implementation.') ;
- writeln ;
- writeln(' Usage: C>UNIT filename') ;
- writeln ;
- writeln(' Insert these codes in your Unit:') ;
- writeln(' {' + InterfaceStart + '} - start of procedure/function interface') ;
- writeln(' {' + InterfaceStart + '} - end of procedure/function interface') ;
- writeln(' {' + IncludeOn + '} - include this procedure/function in interface') ;
- writeln(' {' + IncludeOff + '} - stop including') ;
- halt(0) ;
- end ;
-
- InFileName := UpString(DefExt(paramstr(1), 'PAS')) ;
- OutFileName := ForceExt(InFileName, 'HDR') ;
- TmpFileName := ForceExt(InFileName, 'TMP') ;
-
- assign(InFile, InFileName) ;
- assign(OutFile, OutFileName) ;
- assign(TmpFile, TmpFileName) ;
-
- SetTextBuf(InFile, InBuf) ;
- SetTextBuf(OutFile, OutBuf) ;
- SetTextBuf(TmpFile, TmpBuf) ;
-
- reset(InFile) ;
- if (IOresult <> 0) then
- begin
- writeln(InFileName, ' not found!', ^G) ;
- halt(0) ;
- end ;
-
- rewrite(OutFile) ;
- writeln(OutFile) ; { Start off with a Blank Line }
-
- write('Reading ', InFileName) ; { Keep the human informed }
-
- Writing := false ;
- while not eof(InFile) do
- begin
- readln(InFile, LineIn) ;
-
- UCLineIn := ' ' + UpString(LineIn) + ' ' ; { Add sentinels }
-
- if contains(IncludeOff)
- then WritingOff ;
-
- if Writing and
- CheckForCode and
- (contains(' VAR ') or
- contains(' CONST ') or
- contains(' TYPE ') or
- contains(' BEGIN '))
- then WritingOff ; { Stop if Code found }
-
- if Writing and
- (BlankLine or
- (length(LineIn) > 0))
- then writeln(OutFile, LineIn) ; { if Not Blank line then save }
-
- if Writing then
- begin
- BlankLine := (length(LineIn) > 0) ;
-
- if contains('(')
- then SemiColon := false ;
- if contains(')')
- then SemiColon := true ;
-
- if SemiColon and
- contains(';')
- then CheckForCode := true ;
- end ;
-
- if contains(IncludeOn)
- then WritingOn ; { turn writing on }
- end ;
-
- close(OutFile) ;
- close(InFile) ;
-
- write(#13, #10, 'Finding Interface') ;
-
- reset(InFile) ;
- reset(OutFile) ;
- rewrite(TmpFile) ;
-
- while not eof(InFile) do
- begin
- readln(InFile, LineIn) ;
- writeln(TmpFile, LineIn) ;
-
- if (pos(InterfaceStart, UpString(LineIn)) > 0)
- then
- begin
- write(#13, #10, 'Deleting Old Interface') ;
- UCLineIn := '' ;
- while not eof(InFile) and
- not contains(InterfaceEnd) and
- not contains('IMPLEMENTATION') do
- begin
- readln(InFile, LineIn) ;
- UCLineIn := UpString(LineIn) ;
- end ;
-
- write(#13, #10, 'Writing New Interface') ;
-
- while not eof(OutFile) do
- begin
- readln(OutFile, TLineIn) ;
- writeln(TmpFile, TLineIn) ;
- end ;
-
- write(#13, #10, 'Copying Implementation') ;
-
- writeln(TmpFile, LineIn) ; { .I- or Implementation }
- end ;
- end ;
-
- close(InFile) ;
- close(OutFile) ;
- close(TmpFile) ;
-
- erase(OutFile) ; { '*.HDR' }
-
- assign(OutFile, ForceExt(InFileName, 'BAK')) ;
- erase(OutFile) ; { '*.BAK' }
- if (IOresult = 0) then {} ; { there may not be a *.BAK file }
-
- rename(InFile, ForceExt(InFileName, 'BAK')) ; { '*.PAS' to '*.BAK' }
- rename(TmpFile, InFileName) ; { '*.TMP' to '*.PAS' }
-
- erase(InFile) ; { '*.BAK' }
- if (IOresult = 0) then {} ; { OK to erase now... }
-
- writeln(#13, #10, '*** Done ***') ; { tell 'sack of mostly water' we've finsihed }
- end.